package Lab11.Q7;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        Object a=new Object();
        Object b=new Object();
        funcThread f1= new funcThread(a,b);
        funcThread f2= new funcThread(b,a);
        new Thread(f1).start();
//        Thread.sleep(500);
        new Thread(f2).start();
//        Thread.sleep(100);
    }

}
class funcThread implements Runnable{
    private Object prev;
    private Object self;
    public funcThread( Object prev, Object self){
        this.prev = prev;
        this.self = self;
    }
    @Override
    public void run() {
        int count=0;
        while(count<26){
            synchronized (prev){
                synchronized (self){
                    if(Thread.currentThread().getName().endsWith("1")){
                        char ans= (char) ('A'+count);
                        if(ans=='Z')
                            System.out.print(ans);
                        else
                            System.out.print(ans+" ");
//                        System.out.println(Thread.currentThread().getName());
                    }else{
                        System.out.print(count*2+1);
                        System.out.print(count*2+2);
//                        System.out.println(Thread.currentThread().getName());

                    }
                    count++;
                    self.notify();
                }
                try{
                    if(count==26)
                        break;
                    else
                        prev.wait(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}